package com.yanqu.road.server.channelserver.cmd.activity.entername;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross3.activity.EnterNameProto;
import com.yanqu.road.server.channelserver.cmd.ChannelCommand;
import com.yanqu.road.server.channelserver.manager.activity.entername.ChannelEnterNameMgr;
import com.yanqu.road.server.channelserver.manager.activity.entername.EnterNameModel;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.protocol.ChannelProtocol;

import java.util.Map;

@Cmd(code = ChannelProtocol.N_ENTER_NAME_ALL_SYNC, desc = "下发报名分组信息")
public class ChannelEnterNameAllSyncCmd extends ChannelCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        EnterNameProto.ChannelEnterNameAllSyncReqMsg reqMsg = EnterNameProto.ChannelEnterNameAllSyncReqMsg.parseFrom(packet.getBytes());
        int activityId = reqMsg.getActivityId();
        if(activityId > 0){
            EnterNameModel model = ChannelEnterNameMgr.getEnterNameModelMap().get(activityId);
            if(model != null){
                model.syncAllName(reqMsg.getChannelId());
            }
        }else {
            for (Map.Entry<Integer, EnterNameModel> entry : ChannelEnterNameMgr.getEnterNameModelMap().entrySet()) {
                EnterNameModel model = entry.getValue();
                if(System.currentTimeMillis() / 1000 > model.getActivityInfo().getEndShowTime()){
                    continue;
                }
                model.syncAllName(reqMsg.getChannelId());
            }
        }
    }

    @Override
    public void sendData() {

    }
}
